*---- Authors: Maria Nordbrandt, Gina Gustavsson, Karen Nielsen Breidahl
*---- The Unifying Magic, EJPR 2025


***************************************************************

***AFFECTIVE POLARIZATION


*DENMARK

*UNWEIGHTED MARRY INDEX 

foreach x of varlist Q5_1_DK-Q5_12_DK {
local i= `i'+ 1
gen party`i'_DK=7-`x' 
}

*reversed so that higher values indikate more like

gen marry_sociald=7-Q5_1_DK
gen marry_venstre=7-Q5_2_DK
gen marry_moderat=7-Q5_3_DK
gen marry_socfolke=7-Q5_4_DK
gen marry_danmarksd=7-Q5_5_DK
gen marry_liberal=7-Q5_6_DK
gen marry_konserv=7-Q5_7_DK
gen marry_enheds=7-Q5_8_DK
gen marry_radikale=7-Q5_9_DK
gen marry_danskfolk=7-Q5_10_DK
gen marry_alternativ=7-Q5_11_DK
gen marry_nyeborg=7-Q5_12_DK


*take the mean feeling towards all parties across waves
egen marry_mean_row_dk=rowmean(marry_sociald marry_venstre marry_moderat marry_socfolke marry_danmarksd marry_liberal marry_konserv marry_enheds marry_radikale marry_danskfolk marry_alternativ marry_nyeborg)


*take the difference between each party feeling from the mean
bysort caseid: gen marry_sociald_diff=(marry_sociald-marry_mean_row_dk)^2
bysort caseid: gen marry_venstre_diff=(marry_venstre-marry_mean_row_dk)^2
bysort caseid: gen marry_moderat_diff=(marry_moderat-marry_mean_row_dk)^2
bysort caseid: gen marry_socfolke_diff=(marry_socfolke-marry_mean_row_dk)^2
bysort caseid: gen marry_danmarksd_diff=(marry_danmarksd-marry_mean_row_dk)^2
bysort caseid: gen marry_liberal_diff=(marry_liberal-marry_mean_row_dk)^2
bysort caseid: gen marry_konserv_diff=(marry_konserv-marry_mean_row_dk)^2
bysort caseid: gen marry_enheds_folke_diff=(marry_enheds-marry_mean_row_dk)^2
bysort caseid: gen marry_radikale_diff=(marry_radikale-marry_mean_row_dk)^2
bysort caseid: gen marry_danskfolk_diff=(marry_danskfolk-marry_mean_row_dk)^2
bysort caseid: gen marry_alternativ_diff=(marry_alternativ-marry_mean_row_dk)^2
bysort caseid: gen marry_nyeborg_diff=(marry_nyeborg-marry_mean_row_dk)^2

			*ONLY FOR NEGATIVE PARTISANHIP
			bysort caseid: gen marry_sociald_diff_2=(marry_sociald-marry_mean_row_dk)
			bysort caseid: gen marry_venstre_diff_2=(marry_venstre-marry_mean_row_dk)
			bysort caseid: gen marry_moderat_diff_2=(marry_moderat-marry_mean_row_dk)
			bysort caseid: gen marry_socfolke_diff_2=(marry_socfolke-marry_mean_row_dk)
			bysort caseid: gen marry_danmarksd_diff_2=(marry_danmarksd-marry_mean_row_dk)
			bysort caseid: gen marry_liberal_diff_2=(marry_liberal-marry_mean_row_dk)
			bysort caseid: gen marry_konserv_diff_2=(marry_konserv-marry_mean_row_dk)
			bysort caseid: gen marry_enheds_folke_diff_2=(marry_enheds-marry_mean_row_dk)
			bysort caseid: gen marry_radikale_diff_2=(marry_radikale-marry_mean_row_dk)
			bysort caseid: gen marry_danskfolk_diff_2=(marry_danskfolk-marry_mean_row_dk)
			bysort caseid: gen marry_alternativ_diff_2=(marry_alternativ-marry_mean_row_dk)
			bysort caseid: gen marry_nyeborg_diff_2=(marry_nyeborg-marry_mean_row_dk)



*sum it up
egen marry_sum_dk=rowtotal(marry_sociald_diff marry_venstre_diff marry_moderat_diff marry_socfolke_diff marry_danmarksd_diff marry_liberal_diff marry_konserv_diff marry_enheds_folke_diff marry_radikale_diff marry_danskfolk_diff marry_alternativ_diff marry_nyeborg_diff), missing

*divide by number of parties and take the square root
		
gen marry_sum_mean_dk=(marry_sum_dk/12)
		
gen marry_sq_dk=sqrt(marry_sum_mean_dk)
		
*normalize
gen marry_dk=(marry_sq_dk-0)/(2.266912-0)


************************************************

*WEIGHTED MARRY INDEX DENMARK


*WEIGHTED marry INDEX


*weight each party like by the vote share to use for the next step
gen marry_sociald_w=(marry_sociald*0.2750)
gen marry_venstre_w=(marry_venstre*0.1331)
gen marry_moderat_w=(marry_moderat*0.0927)
gen marry_socfolke_w=(marry_socfolke*0.0830)
gen marry_danmarksd_w=(marry_danmarksd*0.0812)
gen marry_liberal_w=(marry_liberal*0.0788)
gen marry_konserv_w=(marry_konserv*0.0551)
gen marry_enheds_w=(marry_enheds*0.0514)
gen marry_radikale_w=(marry_radikale*0.0379)
gen marry_danskfolk_w=(marry_danskfolk*0.0264)
gen marry_alternativ_w=(marry_alternativ*0.0333)
gen marry_nyeborg_w=(marry_nyeborg*0.0367)

**then sum (rowtotal) all of the weighted marry_p1_w etc to get the average weighted like-i in line with Wagner
egen marry_mean_row_dk_w=rowtotal(marry_sociald_w marry_venstre_w marry_moderat_w marry_socfolke_w marry_danmarksd_w marry_liberal_w marry_konserv_w marry_enheds_w marry_radikale_w marry_danskfolk_w marry_alternativ_w marry_nyeborg_w)

*drop marry_mean_row_dk_w

*then weight each party deviation from the weighted mean by the vote share. noet that it shoul dbe the UNweighted 
*party like score that is used!!!
			
			bysort caseid: gen marry_sociald_w_dk=0.2750*(marry_sociald-marry_mean_row_dk_w)
			bysort caseid: gen marry_sociald_w_dk_sq=marry_sociald_w_dk^2
			bysort caseid: gen marry_venstre_w_dk=0.1331*(marry_venstre-marry_mean_row_dk_w)
			bysort caseid: gen marry_venstre_w_dk_sq=marry_venstre_w_dk^2
			bysort caseid: gen marry_moderat_w_dk=0.0927*(marry_moderat-marry_mean_row_dk_w)
			bysort caseid: gen marry_moderat_w_dk_sq=marry_moderat_w_dk^2
			bysort caseid: gen marry_socfolke_w_dk=0.0830*(marry_socfolke-marry_mean_row_dk_w)
			bysort caseid: gen marry_socfolke_w_dk_sq=marry_socfolke_w_dk^2
			bysort caseid: gen marry_danmarksd_w_dk=0.0812*(marry_danmarksd-marry_mean_row_dk_w)
			bysort caseid: gen marry_danmarksd_w_dk_sq=marry_danmarksd_w_dk^2
			bysort caseid: gen marry_liberal_w_dk=0.0788*(marry_liberal-marry_mean_row_dk_w)
			bysort caseid: gen marry_liberal_w_dk_sq=marry_liberal_w_dk^2
			bysort caseid: gen marry_konserv_w_dk=0.0551*(marry_konserv-marry_mean_row_dk_w)
			bysort caseid: gen marry_konserv_w_dk_sq=marry_konserv_w_dk^2
			bysort caseid: gen marry_enheds_w_dk=0.0514*(marry_enheds-marry_mean_row_dk_w)
			bysort caseid: gen marry_enheds_w_dk_sq=marry_enheds_w_dk^2
			bysort caseid: gen marry_radikale_w_dk=0.0379*(marry_radikale-marry_mean_row_dk_w)
			bysort caseid: gen marry_radikale_w_dk_sq=marry_radikale_w_dk^2
			bysort caseid: gen marry_danskfolk_w_dk=0.0264*(marry_danskfolk-marry_mean_row_dk_w)
			bysort caseid: gen marry_danskfolk_w_dk_sq=marry_danskfolk_w_dk^2
			bysort caseid: gen marry_alternativ_w_dk=0.0333*(marry_alternativ-marry_mean_row_dk_w) 
			bysort caseid: gen marry_alternativ_w_dk_sq=marry_alternativ_w_dk^2
			bysort caseid: gen marry_nyeborg_w_dk=0.0367*(marry_nyeborg-marry_mean_row_dk_w)
			bysort caseid: gen marry_nyeborg_w_dk_sq=marry_nyeborg_w_dk^2

			*drop marry_sociald_w_dk-marry_nyeborg_w_dk_sq
 
 *then sum it all together  
egen marry_sum_dk_w=rowtotal(marry_sociald_w_dk_sq marry_venstre_w_dk_sq marry_moderat_w_dk_sq marry_socfolke_w_dk_sq marry_danmarksd_w_dk_sq marry_liberal_w_dk_sq marry_konserv_w_dk_sq marry_enheds_w_dk_sq marry_radikale_w_dk_sq marry_danskfolk_w_dk_sq marry_alternativ_w_dk_sq marry_nyeborg_w_dk_sq)

*drop marry_sum_dk_w

*lastly take the square root as Harteveld does	
bysort caseid: gen marry_sq_dk_w=sqrt(marry_sum_dk_w)
*drop marry_sq_dk_w

*normalize
sum marry_sq_dk_w
gen marry_dk_w=(marry_sq_dk_w-0)/(0.9467201-0)
sum marry_dk_w
*drop marry_dk_w

******************************************************

	
*UNWEIGHTED MEAN DISTANCE FROM MOST LIKED PARTY DISLIKE
							
	*the value for the most liked party in any of the waves
	egen party_max_dk=rowmax(marry_sociald marry_venstre marry_moderat marry_socfolke marry_danmarksd marry_liberal marry_konserv marry_enheds marry_radikale marry_danskfolk marry_alternativ marry_nyeborg)
	
	by caseid: egen party_max_mean_dk=mean(party_max_dk)
							
	*like_ip-like_max^2
	*take the difference between each party feeling from the mean
	bysort caseid: gen marry_sociald_max=(marry_sociald-party_max_mean_dk)^2
	bysort caseid: gen marry_venstre_max=(marry_venstre-party_max_mean_dk)^2
	bysort caseid: gen marry_moderat_max=(marry_moderat-party_max_mean_dk)^2
	bysort caseid: gen marry_socfolke_max=(marry_socfolke-party_max_mean_dk)^2
	bysort caseid: gen marry_danmarksd_max=(marry_danmarksd-party_max_mean_dk)^2
	bysort caseid: gen marry_liberal_max=(marry_liberal-marry_mean_row_dk)^2
	bysort caseid: gen marry_konserv_max=(marry_konserv-party_max_mean_dk)^2
	bysort caseid: gen marry_enheds_folke_max=(marry_enheds-party_max_mean_dk)^2
	bysort caseid: gen marry_radikale_max=(marry_radikale-party_max_mean_dk)^2
	bysort caseid: gen marry_danskfolk_max=(marry_danskfolk-party_max_mean_dk)^2
	bysort caseid: gen marry_alternativ_max=(marry_alternativ-party_max_mean_dk)^2
	bysort caseid: gen marry_nyeborg_max=(marry_nyeborg-party_max_mean_dk)^2

						
				
	*sum it up
	egen party_max_sum_dk=rowtotal(marry_sociald_max marry_venstre_max marry_moderat_max marry_socfolke_max marry_danmarksd_max marry_liberal_max marry_konserv_max marry_enheds_folke_max marry_radikale_max marry_danskfolk_max marry_alternativ_max marry_nyeborg_max), missing
								
	*divide by number of parties and take the square root
	by caseid: gen party_max_tot_dk=sqrt(party_max_sum_dk/12)
													
	gen marry_dist_n_dk=(party_max_tot_dk-0)/ (4.372684-0)
	
**********************************************************************

*WEIGHTED MEAN DISTANCE FROM MOST LIKED marry
								
	*multiply the vote share of each party by (like_ip-like_p_mean_max)^2 
	bysort caseid: gen marry_sociald_max_w=0.2750*(marry_sociald-party_max_mean_dk)
	bysort caseid: gen marry_sociald_max_w_sq=marry_sociald_max_w^2
	bysort caseid: gen marry_venstre_max_w=0.1331*(marry_venstre-party_max_mean_dk)
	bysort caseid: gen marry_venstre_max_w_sq=marry_venstre_max_w^2
	bysort caseid: gen marry_moderat_max_w=0.0927*(marry_moderat-party_max_mean_dk)
	bysort caseid: gen marry_moderat_max_w_sq=marry_moderat_max_w^2
	bysort caseid: gen marry_socfolke_max_w=0.0830*(marry_socfolke-party_max_mean_dk)
	bysort caseid: gen marry_socfolke_max_w_sq=marry_socfolke_max_w^2
	bysort caseid: gen marry_danmarksd_max_w=0.0812*(marry_danmarksd-party_max_mean_dk)
	bysort caseid: gen marry_danmarksd_max_w_sq=marry_danmarksd_max_w^2
	bysort caseid: gen marry_liberal_max_w=0.0788*(marry_liberal-party_max_mean_dk)
	bysort caseid: gen marry_liberal_max_w_sq=marry_liberal_max_w^2
	bysort caseid: gen marry_konserv_max_w=0.0551*(marry_konserv-party_max_mean_dk)
	bysort caseid: gen marry_konserv_max_w_sq=marry_konserv_max_w^2
	bysort caseid: gen marry_enheds_folke_max_w=0.0514*(marry_enheds-party_max_mean_dk)
	bysort caseid: gen marry_enheds_folke_max_w_sq=marry_enheds_folke_max_w^2
	bysort caseid: gen marry_radikale_max_w=0.0379*(marry_radikale-party_max_mean_dk)
	bysort caseid: gen marry_radikale_max_w_sq=marry_radikale_max_w^2
	bysort caseid: gen marry_danskfolk_max_w=0.0264*(marry_danskfolk-party_max_mean_dk)
	bysort caseid: gen marry_danskfolk_max_w_sq=marry_danskfolk_max_w^2
	bysort caseid: gen marry_alternativ_max_w=0.0333*(marry_alternativ-party_max_mean_dk)
	bysort caseid: gen marry_alternativ_max_w_sq=marry_alternativ_max_w^2
	bysort caseid: gen marry_nyeborg_max_w=0.0367*(marry_nyeborg-party_max_mean_dk)
	bysort caseid: gen marry_nyeborg_max_w_sq=marry_nyeborg_max_w^2
	

	*sum it up
	egen marry_symp_sum_max_dk=rowtotal(marry_sociald_max_w_sq marry_venstre_max_w_sq marry_moderat_max_w_sq marry_socfolke_max_w_sq marry_danmarksd_max_w_sq marry_liberal_max_w_sq marry_konserv_max_w_sq marry_enheds_folke_max_w_sq marry_radikale_max_w_sq marry_danskfolk_max_w_sq marry_alternativ_max_w_sq marry_nyeborg_max_w_sq)
	
	
	by caseid: gen marry_symp_max_v_dk=sqrt(marry_symp_sum_max_dk)
	
	gen marry_dist_n_dk_w=(marry_symp_max_v_dk-0)/ ( 1.758059-0)

	
	
	
	
								

******************************************************************************



*SWEDEN

*UNWEIGHTED MARRY INDEX 
*reversed SO THAT higher values more happy

gen marry_socdem=7-Q5_1_SE
gen marry_vp=7-Q5_2_SE
gen marry_mp=7-Q5_3_SE
gen marry_cent=7-Q5_4_SE
gen marry_lib=7-Q5_5_SE
gen marry_mod=7-Q5_6_SE
gen marry_kd=7-Q5_7_SE
gen marry_sd=7-Q5_8_SE



*take the mean feeling towards all parties across waves
egen marry_mean_row_se=rowmean(marry_socdem marry_vp marry_mp marry_cent marry_lib marry_mod marry_kd marry_sd)


*take the difference between each party feeling from the mean
bysort caseid: gen marry_socdem_diff=(marry_socdem-marry_mean_row_se)^2
bysort caseid: gen marry_vp_diff=(marry_vp-marry_mean_row_se)^2
bysort caseid: gen marry_mp_diff=(marry_mp-marry_mean_row_se)^2
bysort caseid: gen marry_cent_diff=(marry_cent-marry_mean_row_se)^2
bysort caseid: gen marry_lib_diff=(marry_lib-marry_mean_row_se)^2
bysort caseid: gen marry_mod_diff=(marry_mod-marry_mean_row_se)^2
bysort caseid: gen marry_kd_diff=(marry_kd-marry_mean_row_se)^2
bysort caseid: gen marry_sd_diff=(marry_sd-marry_mean_row_se)^2

			**ONLY FOR NEGATIVE PARTISANSHIP (REVERSED SO THAT HIGHER VALUES = MORE HAPPY)
		
			bysort caseid: gen marry_socdem_diff_2=(marry_socdem-marry_mean_row_se)
			bysort caseid: gen marry_vp_diff_2=(marry_vp-marry_mean_row_se)
			bysort caseid: gen marry_mp_diff_2=(marry_mp-marry_mean_row_se)
			bysort caseid: gen marry_cent_diff_2=(marry_cent-marry_mean_row_se)
			bysort caseid: gen marry_lib_diff_2=(marry_lib-marry_mean_row_se)
			bysort caseid: gen marry_mod_diff_2=(marry_mod-marry_mean_row_se)
			bysort caseid: gen marry_kd_diff_2=(marry_kd-marry_mean_row_se)
			bysort caseid: gen marry_sd_diff_2=(marry_sd-marry_mean_row_se)


*sum it up
egen marry_sum_se=rowtotal(marry_socdem_diff marry_vp_diff marry_mp_diff marry_cent_diff marry_lib_diff marry_mod_diff marry_kd_diff marry_sd_diff), missing

*divide by number of parties and take the square root
		
gen marry_sum_mean_se=(marry_sum_se/8)
		
gen marry_sq_se=sqrt(marry_sum_mean_se)
		
*normalize
gen marry_se=(marry_sq_se-0)/(2.5-0)


egen marry_n=rowtotal(marry_dk marry_se), missing


************************************************



*WEIGHTED marry INDEX

*Same as for Denmark

gen marry_socdem_w=(marry_socdem*0.3033)
gen marry_vp_w=(marry_vp*0.0675)
gen marry_mp_w=(marry_mp*0.0508)
gen marry_cent_w=(marry_cent*0.0671)
gen marry_lib_w=(marry_lib*0.0461)
gen marry_mod_w=(marry_mod*0.1910)
gen marry_kd_w=(marry_kd*0.0534)
gen marry_sd_w=(marry_sd*0.2054)

**then sum (rowtotal) all of marry_p1_w etc  to get the weighted average like-i etc. 
egen marry_mean_row_se_w=rowtotal(marry_socdem_w marry_vp_w marry_mp_w marry_cent_w marry_lib_w marry_mod_w marry_kd_w marry_sd_w)
*drop marry_mean_row_se_w

*then weight each party deviation by the vote share using the UNweighted like-score
 
			bysort caseid: gen marry_socdem_w_se=0.3033*(marry_socdem-marry_mean_row_se_w)
			bysort caseid: gen marry_socdem_w_se_sq=marry_socdem_w_se^2
			bysort caseid: gen marry_vp_w_se=0.0675*(marry_vp-marry_mean_row_se_w)
			bysort caseid: gen marry_vp_w_se_sq=marry_vp_w_se^2
			bysort caseid: gen marry_mp_w_se=0.0508*(marry_mp-marry_mean_row_se_w)
			bysort caseid: gen marry_mp_w_se_sq=marry_mp_w_se^2
			bysort caseid: gen marry_cent_w_se=0.0671*(marry_cent-marry_mean_row_se_w)
			bysort caseid: gen marry_cent_w_se_sq=marry_cent_w_se^2
			bysort caseid: gen marry_lib_w_se=0.0461*(marry_lib-marry_mean_row_se_w)
			bysort caseid: gen marry_lib_w_se_sq=marry_lib_w_se^2
			bysort caseid: gen marry_mod_w_se=0.1910*(marry_mod-marry_mean_row_se_w)
			bysort caseid: gen marry_mod_w_se_sq=marry_mod_w_se^2
			bysort caseid: gen marry_kd_w_se=0.0534*(marry_kd-marry_mean_row_se_w)
			bysort caseid: gen marry_kd_w_se_sq=marry_kd_w_se^2
			bysort caseid: gen marry_sd_w_se=0.2054*(marry_sd-marry_mean_row_se_w)
			bysort caseid: gen marry_sd_w_se_sq=marry_sd_w_se^2
			
			*drop marry_socdem_w_se-marry_sd_w_se_sq
			
 *then sum it all together  
egen marry_sum_se_w=rowtotal(marry_socdem_w_se_sq marry_vp_w_se_sq marry_mp_w_se_sq marry_cent_w_se_sq marry_lib_w_se_sq marry_mod_w_se_sq marry_kd_w_se_sq marry_sd_w_se_sq), missing
*drop marry_sum_se_w

*lastly take the square root as Harteveld does	
bysort caseid: gen marry_sum_se_w_sqr=sqrt(marry_sum_se_w)
*drop marry_sum_se_w_sqr

*normalize
sum marry_sum_se_w_sqr
gen marry_se_w=(marry_sum_se_w_sqr-.0066645 )/(1.127672-.0066645 )
sum marry_se_w
*drop marry_se_w

*COMBINE SWEDEN AND DENMARK
egen marry_n_w=rowtotal(marry_dk_w marry_se_w), missing
sum marry_n_w
*drop marry_n_w
************************************************************************

*UNWEIGHTED MEAN DISTANCE FROM MOST LIKED PARTY 
							
	*the value for the most liked party in any of the waves
	egen party_max_se=rowmax(marry_socdem marry_vp marry_mp marry_cent marry_lib marry_mod marry_kd marry_sd)
	
	by caseid: egen party_max_mean_se=mean(party_max_se)
	
							
	*like_ip-like_max^2
	*take the difference between each party feeling from the mean
	bysort caseid: gen marry_socdem_max=(marry_socdem_w-party_max_mean_se)^2
	bysort caseid: gen marry_vp_max=(marry_vp_w-party_max_mean_se)^2
	bysort caseid: gen marry_mp_max=(marry_mp_w-party_max_mean_se)^2
	bysort caseid: gen marry_cent_max=(marry_cent_w-party_max_mean_se)^2
	bysort caseid: gen marry_lib_max=(marry_lib_w-party_max_mean_se)^2
	bysort caseid: gen marry_mod_max=(marry_mod_w-party_max_mean_se)^2
	bysort caseid: gen marry_kd_max=(marry_kd_w-party_max_mean_se)^2
	bysort caseid: gen marry_sd_max=(marry_sd_w-party_max_mean_se)^2
					
				
	*sum it up
	egen party_max_sum_se=rowtotal(marry_socdem_max marry_vp_max marry_mp_max marry_cent_max marry_lib_max marry_mod_max marry_kd_max marry_sd_max), missing
								
	*divide by number of parties and take the square root
	by caseid: gen party_max_tot_se=sqrt(party_max_sum_se/8)
													
	gen marry_dist_n_se=(party_max_tot_se-0.8816233)/ ( 5.836111-0.8816233)
	
egen marry_dist_n=rowtotal(marry_dist_n_dk marry_dist_n_se), missing

*****************************************************************************


	*WEIGHTED MEAN DISTANCE FROM MOST LIKED marry

								
	*multiply the vote share of each party by (like_ip-like_p_mean_max)^2 
	bysort caseid: gen marry_socdem_max_w=0.3033*(marry_socdem-party_max_mean_se)
	bysort caseid: gen marry_socdem_max_w_sq=marry_socdem_max_w^2
	bysort caseid: gen marry_vp_max_w=0.0675*(marry_vp-party_max_mean_se)
	bysort caseid: gen marry_vp_max_w_sq=marry_vp_max_w^2
	bysort caseid: gen marry_mp_max_w=0.0508*(marry_mp-party_max_mean_se)
	bysort caseid: gen marry_mp_max_w_sq=marry_mp_max_w^2
	bysort caseid: gen marry_cent_max_w=0.0671*(marry_cent-party_max_mean_se)
	bysort caseid: gen marry_cent_max_w_sq=marry_cent_max_w^2
	bysort caseid: gen marry_lib_max_w=0.0461*(marry_lib-party_max_mean_se)
	bysort caseid: gen marry_lib_max_w_sq=marry_lib_max_w^2
	bysort caseid: gen marry_mod_max_w=0.1910*(marry_mod-party_max_mean_se)
	bysort caseid: gen marry_mod_max_w_sq=marry_mod_max_w^2
	bysort caseid: gen marry_kd_max_w=0.0534*(marry_kd-party_max_mean_se)
	bysort caseid: gen marry_kd_max_w_sq=marry_kd_max_w^2
	bysort caseid: gen marry_sd_max_w=0.2054*(marry_sd-party_max_mean_se)
	bysort caseid: gen marry_sd_max_w_sq=marry_sd_max_w^2

	
	
	*sum it up
	egen marry_symp_sum_max_se=rowtotal(marry_socdem_max_w_sq marry_vp_max_w_sq marry_mp_max_w_sq marry_cent_max_w_sq marry_lib_max_w_sq marry_mod_max_w_sq marry_kd_max_w_sq marry_sd_max_w_sq)
	
	
	by caseid: gen marry_symp_max_v_se=sqrt(marry_symp_sum_max_se)
	
	gen marry_dist_n_se_w=(marry_symp_max_v_se-0)/ ( 2.137293-0)
	
	
	
*COMBINE SWEDEN AND DENMARK
egen marry_dist_n_w=rowtotal(marry_dist_n_dk_w marry_dist_n_se_w), missing
	